package com.elean.springboot.superprint.autoconfigure;


import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @program: elean-commons
 * @description: ${description}
 * @author: ly
 * @create: 2019-09-18 14:55
 **/

@Configuration
@EnableConfigurationProperties(value = SuperprintProperties.class)//给容器中添加此配置文件
@ConditionalOnMissingBean(SuperprintUtil.class)//当容器中缺少SuperprintUtil时才创建此自动配置类
public class SuperprintAutoConfiguration {
    @Bean
    public SuperprintUtil SuperprintUtil(){
        return new SuperprintUtil();
    }
    @Bean(name = "spRestTemplate")
    public RestTemplate spRestTemplate(){
        OkHttp3ClientHttpRequestFactory factory = new OkHttp3ClientHttpRequestFactory();
        factory.setConnectTimeout(6 * 1000);
        factory.setReadTimeout(6 * 1000);
        factory.setWriteTimeout(6 * 1000);
        return new RestTemplate(factory);
    }
}
